package com.trinity.oldsystem.controller;

import com.trinity.common.annotation.Log;
import com.trinity.common.core.controller.BaseController;
import com.trinity.common.core.domain.AjaxResult;
import com.trinity.common.core.page.TableDataInfo;
import com.trinity.common.enums.BusinessType;
import com.trinity.common.utils.poi.ExcelUtil;
import com.trinity.oldsystem.domain.DhxhBooklist;
import com.trinity.oldsystem.service.IDhxhBooklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 老系统数目清单Controller
 *
 * @author old-system
 * @date 2024-01-30
 */
@RestController
@RequestMapping("/oldsystem/booklist")
public class DhxhBooklistController extends BaseController {
    @Autowired
    private IDhxhBooklistService dhxhBooklistService;

    /**
     * 查询老系统数目清单列表
     */
    @PreAuthorize("@ss.hasPermi('oldsystem:booklist:list')")
    @GetMapping("/list")
    public TableDataInfo list(DhxhBooklist dhxhBooklist) {
        startPage();
        List<DhxhBooklist> list = dhxhBooklistService.selectDhxhBooklistList(dhxhBooklist);
        return getDataTable(list);
    }

    /**
     * 导出老系统数目清单列表
     */
    @PreAuthorize("@ss.hasPermi('oldsystem:booklist:export')")
    @Log(title = "老系统数目清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DhxhBooklist dhxhBooklist) {
        List<DhxhBooklist> list = dhxhBooklistService.selectDhxhBooklistList(dhxhBooklist);
        ExcelUtil<DhxhBooklist> util = new ExcelUtil<DhxhBooklist>(DhxhBooklist.class);
        util.exportExcel(response, list, "老系统数目清单数据");
    }

    /**
     * 获取老系统数目清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('oldsystem:booklist:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(dhxhBooklistService.selectDhxhBooklistById(id));
    }

    /**
     * 新增老系统数目清单
     */
    @PreAuthorize("@ss.hasPermi('oldsystem:booklist:add')")
    @Log(title = "老系统数目清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DhxhBooklist dhxhBooklist) {
        return toAjax(dhxhBooklistService.insertDhxhBooklist(dhxhBooklist));
    }

    /**
     * 修改老系统数目清单
     */
    @PreAuthorize("@ss.hasPermi('oldsystem:booklist:edit')")
    @Log(title = "老系统数目清单", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody DhxhBooklist dhxhBooklist) {
        return toAjax(dhxhBooklistService.updateDhxhBooklist(dhxhBooklist));
    }

    /**
     * 删除老系统数目清单
     */
    @PreAuthorize("@ss.hasPermi('oldsystem:booklist:remove')")
    @Log(title = "老系统数目清单", businessType = BusinessType.DELETE)
    @PostMapping("/{ids}/delete")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(dhxhBooklistService.deleteDhxhBooklistByIds(ids));
    }
}
